const { DataTypes, TINYINT} = require('sequelize')
const sequelize = require('../config/database')

const PropertyModel = sequelize.define('Property', {
  id: {
    type: DataTypes.INTEGER,
    autoIncrement: true,
    allowNull: false,
    primaryKey: true
  },
  title: {
    type: DataTypes.STRING,
    allowNull: false,
  },
  description: {
    type: DataTypes.TEXT,
    allowNull: false,
  },
  address: {
    type: DataTypes.STRING,
    allowNull: false
  },
  resident: {
    type: DataTypes.STRING,
    allowNull: false
  },
  county: {
    type: DataTypes.STRING,
    allowNull: false
  },
  city: {
    type: DataTypes.STRING,
    allowNull: false
  },
  province: {
    type: DataTypes.STRING,
    allowNull: false
  },
  longitude: {
    type: DataTypes.DECIMAL(9, 6),
    allowNull: false
  },
  latitude: {
    type: DataTypes.DECIMAL(9, 6),
    allowNull: false
  },
  room_count: {
    type: DataTypes.INTEGER,
    allowNull: false
  },
  livingroom_count: {
    type: DataTypes.INTEGER,
    allowNull: false
  },
  bathroom_count: {
    type: DataTypes.INTEGER,
    allowNull: false
  },
  room_area: {
    type: DataTypes.DECIMAL(10, 2),
    allowNull: false
  },
  price: {
    type: DataTypes.DECIMAL(10, 2),
    allowNull: false
  },
  image_url: {
    type: DataTypes.JSON,
    allowNull: false
  },
  room_type: {
    type: DataTypes.ENUM('公寓', '别墅', '普通住宅'),
    allowNull: false
  },
  decorate_type: {
    type: DataTypes.ENUM('基础装修', '精装修', '局部改造'),
    allowNull: false
  },
  rent_type: {
    type: DataTypes.ENUM('整租', '合租', '长租', '短租'),
    allowNull: false
  },
  floor: {
    type: DataTypes.STRING,
    allowNull: false
  },
  room_direction: {
    type: DataTypes.ENUM('东', '南', '西', '北', '东北', '西北', '东南', '西南'),
    allowNull: false
  },
  bedroom_facility: {
    type: DataTypes.JSON,
    allowNull: false
  },
  public_facility: {
    type: DataTypes.JSON,
    allowNull: false
  },
  publish_date: {
    type: DataTypes.DATE
  },
  admin_id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    references: {
      model: 'admin',
      key: 'id'
    },
  },
  is_hot: {
    type: TINYINT,
    allowNull: false,
    defaultValue: 0
  },
  createdAt: {
    type: DataTypes.TIME
  },
  updatedAt: {
    type: DataTypes.TIME,
  }
}, {
  freezeTableName: true,
  timestamps: false,
  tableName: 'property'
})

module.exports = PropertyModel